#维护表，代表一列车一次完整的维护总任务
class CreateMaintenances < ActiveRecord::Migration
  def self.up
    create_table :maintenances do |t|
      t.integer   :train_task_id                                  #火车维护任务id
      t.integer   :work_id                                        #工作id
      t.integer   :team_id                                        #团队id
      t.datetime  :begin_time                                     #应开始时间
      t.datetime  :finish_time                                    #应结束时间
      t.integer   :worker_id                                      #打卡人的id
      t.datetime  :check_in_time                                  #刷卡进入时间，由刷卡机得到
      t.datetime  :check_out_time                                 #刷卡离开时间，有刷卡机得到

      #以下各字段，不进行存储。只用作生成chart时，进行数据传送
      t.string    :title                                          #用于标示当前标题
      t.integer   :head_minute                                    #计划规定时间与18点的距离分钟数，用于显示fullChart
      t.integer   :begin_minute                                   #开始时间距离规定时间的分钟数
      t.integer   :un_start_minute                                #未开时进行的分钟数，灰色
      t.integer   :during_minute                                  #正在进行的分钟数，红色
      t.integer   :finish_minute                                  #结束的分钟数，绿色
      t.integer   :foot_minute                                    #工作结束后（3种状态）与第二天8点的距离分钟数，用于显示fullChart
      t.integer   :end_minute                                     #手动结束分钟数，暗红色

      #任务状态标志位  "0:未开始"、"1:进行中，静态作业"、"2:静态已完成,开始动态任务"、
      #"3:手动结束未完成的静态任务，开始动态作业"、"4:静态已完成,动态作业完成"、
      #"5:静态已完成,动态作业手动结束"、"6:手动结束未完成的静态任务，动态作业完成"、"7:手动结束未完成的静态任务，动态作业手动结束"
      t.string    :flag          ,:default => 0                   
      t.text      :description                                    #备注

      t.integer   :is_locked     ,:limit => 1 ,:default => 0      #锁定 1为True 0为False
      t.integer   :lock_version  ,:default => 0                   #乐观锁
      t.timestamps
    end

    #添加数据
    Maintenance.create(:train_task_id => "1",:work_id => "1" ,:team_id => "1",
      :begin_time => "2010-08-25 18:35:06" ,:finish_time => "2010-08-25 18:55:06",
      :flag => "2")
    Maintenance.create(:train_task_id => "1",:work_id => "2" ,:team_id => "2",
      :begin_time => "2010-08-25 18:55:06" ,:finish_time => "2010-08-25 19:55:06",
      :flag => "2")
    Maintenance.create(:train_task_id => "1",:work_id => "3" ,:team_id => "3",
      :begin_time => "2010-08-25 20:35:06" ,:finish_time => "2010-08-25 20:55:06",
      :flag => "1")
    Maintenance.create(:train_task_id => "1",:work_id => "4" ,:team_id => "4",
      :begin_time => "2010-08-25 20:45:06" ,:finish_time => "2010-08-25 21:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "1",:work_id => "5" ,:team_id => "5",
      :begin_time => "2010-08-25 21:45:06" ,:finish_time => "2010-08-25 23:55:06",
      :flag => "0")

    Maintenance.create(:train_task_id => "2",:work_id => "1" ,:team_id => "1",
      :begin_time => "2010-08-24 18:35:06" ,:finish_time => "2010-08-24 18:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "2",:work_id => "2" ,:team_id => "2",
      :begin_time => "2010-08-24 18:55:06" ,:finish_time => "2010-08-24 19:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "2",:work_id => "3" ,:team_id => "3",
      :begin_time => "2010-08-24 20:35:06" ,:finish_time => "2010-08-24 20:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "2",:work_id => "4" ,:team_id => "4",
      :begin_time => "2010-08-24 20:45:06" ,:finish_time => "2010-08-24 21:55:06",
      :flag => "0")

    Maintenance.create(:train_task_id => "3",:work_id => "1" ,:team_id => "1",
      :begin_time => "2010-08-23 18:35:06" ,:finish_time => "2010-08-23 18:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "3",:work_id => "2" ,:team_id => "2",
      :begin_time => "2010-08-23 18:55:06" ,:finish_time => "2010-08-23 19:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "3",:work_id => "3" ,:team_id => "3",
      :begin_time => "2010-08-23 20:35:06" ,:finish_time => "2010-08-23 20:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "3",:work_id => "4" ,:team_id => "4",
      :begin_time => "2010-08-23 20:45:06" ,:finish_time => "2010-08-23 21:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "3",:work_id => "5" ,:team_id => "5",
      :begin_time => "2010-08-23 21:45:06" ,:finish_time => "2010-08-23 23:55:06",
      :flag => "0")


    Maintenance.create(:train_task_id => "4",:work_id => "1" ,:team_id => "1",
      :begin_time => "2010-08-22 18:35:06" ,:finish_time => "2010-08-22 18:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "4",:work_id => "2" ,:team_id => "2",
      :begin_time => "2010-08-22 18:55:06" ,:finish_time => "2010-08-22 19:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "4",:work_id => "3" ,:team_id => "3",
      :begin_time => "2010-08-22 20:35:06" ,:finish_time => "2010-08-22 20:55:06",
      :flag => "0")
    Maintenance.create(:train_task_id => "4",:work_id => "4" ,:team_id => "4",
      :begin_time => "2010-08-22 20:45:06" ,:finish_time => "2010-08-22 21:55:06",
      :flag => "0")

  end

  def self.down
    drop_table :maintenances
  end
end
